package org.zxp.thread.volatileTest.singleton;

/**
 * @program: zxp-thread-test
 * @description: 饿汉单例模式，类加载后已经把单例实例准备好了，但是如果不使用单例对象就浪费了内存空间
 * @author: X-Pacific zhang
 * @create: 2019-05-10 17:37
 **/
public class HungrySingleton {
    private static HungrySingleton hungrySingleton = new HungrySingleton();
    private HungrySingleton(){
    }
    public static HungrySingleton getInstance(){
        return hungrySingleton;
    }

    public static void main(String[] args){
        for (int i = 0; i < 100; i++) {
            new Thread(() -> {
                System.out.println(HungrySingleton.getInstance().hashCode());
            }).start();
        }
    }
}
